/**
 * 数列有序!
 * 有n(n<=100)个整数，已经按照从小到大顺序排列好，现在另外给一个整数x，请将该数插入到序列中，并使新的序列仍然有序。
 * input:输入数据包含多个测试实例，每组数据由两行组成，第一行是n和m，第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束，本行不做处理。
 * output:对于每个测试实例，输出插入新的元素后的数列。
 */
#include <iostream>
#include <stdexcept>

#define eleType int

using namespace std;

struct ListNode
{
    eleType data;
    ListNode *next;
    ListNode(eleType x) : data(x), next(NULL) {}
};

class LinkedList
{
private:
    ListNode *head;
    int size;
public:
    LinkedList() : head(NULL), size(0) {}
    ~LinkedList();

    // 增
    void insert(int nIndex, eleType element);

    // 删
    void remove(int nIndex);

    // 改
    void update(int nIndex, eleType element);

    // 查
    ListNode *find(eleType element);
    ListNode *get(int nIndex);

    // 打印
    void print();

    // 求和函数
    eleType sum();

    // 插入到尾部
    void append(eleType element);

    // 有序插入
    void ascInsert(eleType element);
};

LinkedList::~LinkedList()
{
    ListNode *pCurr = head;
    while (pCurr != NULL)
    {
        ListNode *pTemp = pCurr;
        pCurr = pCurr->next;
        delete pTemp;
    }
}

void LinkedList::insert(int nIndex, eleType element)
{
    if (nIndex < 0 || nIndex > size) 
    {
        throw std::out_of_range("Index position");
    }
    ListNode *newNode = new ListNode(element);
    if (nIndex == 0)
    {
        newNode->next = head;
        head = newNode;
    }
    else 
    {
        ListNode *pTemp = head;
        for (int i = 1; i < nIndex; ++i)
        {
            pTemp = pTemp->next;
        }
        newNode->next = pTemp->next;
        pTemp->next = newNode;
    }
    size++;
}

void LinkedList::remove(int nIndex)
{
    if (nIndex < 0 || nIndex >= size) 
    {
        throw std::out_of_range("Index position");
    }
    if (nIndex == 0)
    {
        ListNode *pDel = head;
        head = head->next;
        delete pDel;
    }
    else
    {
        ListNode *pTemp = head;
        for (int i = 0; i < nIndex; ++i) 
        {
            pTemp = pTemp->next;
        }
        ListNode *pDel = pTemp->next;
        pTemp->next = pDel->next;
        delete pDel;
    }
    size--;
}

void LinkedList::update(int nIndex, eleType element)
{  
    get(nIndex)->data = element;
}

ListNode *LinkedList::find(eleType element)
{
    ListNode *pTemp = head;
    for (int j = 0; j < size; ++j) 
    {
        if (pTemp->data == element) 
        {
            return pTemp;
        }
        pTemp = pTemp->next;
    }
    return NULL;
}

ListNode *LinkedList::get(int nIndex)
{
    if (nIndex < 0 || nIndex >= size)
    {
        throw std::out_of_range("Index position");
    }
    ListNode *pTemp = head;
    for (int j = 0; j < nIndex; ++j) 
    {
        pTemp = pTemp->next;
    }
    return pTemp;
}

void LinkedList::print() 
{
    ListNode *pTemp = head;
    while (pTemp)
    {
        cout << pTemp->data << " ";
        pTemp = pTemp->next;
    }
    cout << endl;
}

void LinkedList::append(eleType element)
{
    // ListNode *pNewNode = new ListNode(element);
    // ListNode *pTemp = head;
    // while (pTemp)
    // {
    //     pTemp = pTemp->next;
    // }
    // pTemp->next = pNewNode;

    insert(size, element);
}

void LinkedList::ascInsert(eleType element)
{
    if (size == 0)
    {
        insert(0, element);
        return;
    }
    else
    {
        ListNode *pTemp = head;
        for (int i = 0; i < size; ++i)
        {
            if (element <= pTemp->data)
            {
                insert(i, element);
                return;
            }
            pTemp = pTemp->next;
        }
    }
    insert(size, element);
}


int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        if (!n && !m)
        {
            break;
        }
        LinkedList list;
        for (int i = 0; i < n; ++i)
        {
            eleType x;
            cin >> x;
            list.append(x);
        }
        // 插入一个节点
        list.ascInsert(m);       
        list.print(); 
    }
    
    return 0;
}